﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.GamerServices;

using BackgroundTest.BattleFieldManager;
using BackgroundTest.BasicAbstracts;

namespace BackgroundTest.TestObjects
{
    class TestZ
    {
        // The texture for the test object.
        private Texture2D textureUsed;

        public Texture2D TextureUsed
        {
            get { return TextureUsed; }
            set { textureUsed = value; }
        }

        // The position on the screen of the test object.
        private VectorScreen position;

        public VectorScreen Position
        {
            get { return position; }
            set { position = value; }
        }

        // The rectangle position of the object.
        private Rectangle rectanglePosition;

        public Rectangle RectanglePosition
        {
            get { return rectanglePosition; }
            set { rectanglePosition = value; }
        }

        // The depth-buffer of this test object.
        private float zBuffer;

        public float ZBuffer
        {
            get { return zBuffer; }
        }

        // Construction function.
        public TestZ ()
        {
            position = new VectorScreen(0, 0);
            rectanglePosition = new Rectangle();
            zBuffer = 0.0f;
        }

        // A function to load texture into the object.
        public void LoadTexture ( Texture2D _texture )
        {
            textureUsed = _texture;
        }

        // Object's update function
        public void UpdateTestObject( VectorScreen _position )
        {
            position = _position;
            rectanglePosition.X = position.x;
            rectanglePosition.Y = position.y;
            rectanglePosition.Width = textureUsed.Width;
            rectanglePosition.Height = textureUsed.Height;
        }

        public void UpdateTestObject( int _x, int _y )
        {
            position.x = _x;
            position.y = _y;
            rectanglePosition.X = position.x;
            rectanglePosition.Y = position.y;
            rectanglePosition.Width = textureUsed.Width;
            rectanglePosition.Height = textureUsed.Height;
        }

        // Set Z-buffer
        public void SetZ ( float _zBuffer )
        {
            if ( _zBuffer > 1)
            {
                zBuffer = 1.0f;
            }
            else if ( _zBuffer < 0 )
            {
                zBuffer = 0.0f;
            }
            else zBuffer = _zBuffer;
        }

        // Increase Z-buffer
        public void IncreaseZ ( float _delta )
        {
            zBuffer += _delta;
        }

        // Render function.
        public void Render( SpriteBatch _spriteBatch )
        {
            _spriteBatch.Draw(textureUsed,
                rectanglePosition,
                null,
                Color.White,
                0,
                Vector2.Zero,
                SpriteEffects.None,
                zBuffer);
        }
    }
}
